package com.naiterui.ehp.ps.form.mongo;

import java.util.List;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.ehp.ps.form.bean.DesignForm;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class DesignFormDao extends MongoBaseDao {

    private static final String COLLECTION_NAME = "design_form";
    private final MongoTemplate mongoTemplate;

    public void save(DesignForm designForm) {
        super.save(designForm, COLLECTION_NAME);
    }

    public DesignForm getByFormId(String formId) {
        Query query = new Query();
        Criteria criteria = new Criteria("_id").is(formId);
        query.addCriteria(criteria);
        List<DesignForm> list = super.find(query, DesignForm.class, COLLECTION_NAME);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    protected MongoTemplate getMongoTemplate() {
        return this.mongoTemplate;
    }

}
